package org.example.petsystem.controller;

import org.example.petsystem.entity.ResultBody;
import org.example.petsystem.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/Booking")
@CrossOrigin(origins="*")
public class BookingController {
    //进行预约
    @Autowired
    private BookingService bookingService;
    @RequestMapping("/UserBooking")
    public ResultBody UserBooking(@RequestBody Map<String,Object> map){
        if(map.get("userphone")==null||map.get("buyphone")==null||map.get("bookingtime")==null||map.get("number")==null||map.get("bookingcontent")==null||map.get("price")==null||map.get("bookingday")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        //传入数值
        return bookingService.addBooking(map);
    }
    //展示个人预约信息
    @RequestMapping("/displayUserBooking")
    public ResultBody displayUserBooking(@RequestBody Map<String,Object> map){
        if(map.get("userphone")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        //传入数值
        return bookingService.displayUserBooking(map);
    }
    //展示未审核预约信息
    @RequestMapping("/displayBooking")
    public ResultBody displayBooking(){
        //传入数值
        return bookingService.displayBooking();
    }
    //展示已审核预约信息
    @RequestMapping("/displayBookingR")
    public ResultBody displayBookingR(){
        //传入数值
        return bookingService.displayBookingR();
    }
    //审核预约
    @RequestMapping("/checkBooking")
    public ResultBody checkBooking(@RequestBody Map<String,Object> map){
        if(map.get("id")==null||map.get("decision")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        //传入数值
        return bookingService.checkBooking(map);
    }
    //增加服务
    @RequestMapping("/addservice")
    public ResultBody addservice(@RequestBody Map<String,Object> map){
        if(map.get("servicecontent")==null||map.get("price")==null||map.get("avatarUrl")==null||map.get("topic")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        //传入数值
        return bookingService.addservice(map);
    }
    //修改服务
    @RequestMapping("/updateservice")
    public ResultBody updateservice(@RequestBody Map<String,Object> map){
        if(map.get("id")==null&&map.get("servicecontent")==null&&map.get("price")==null&&map.get("avatarUrl")==null||map.get("topic")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        //传入数值
        return bookingService.updateservice(map);
    }
    //删除服务
    @RequestMapping("/delservice")
    public ResultBody delservice(@RequestBody Map<String,Object> map){
        if(map.get("id")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        //传入数值
        return bookingService.delservice(map);
    }
    //展示服务
    @RequestMapping("/displayservice")
    public ResultBody displayservice(){
        //传入数值
        return bookingService.displayservice();
    }
    //申请退款的接口

}
